﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using ElectronicJournal.Account;

namespace ElectronicJournal
{
    public partial class Reviewer : System.Web.UI.Page
    {
        DataTable ArticleTable = new DataTable();
        DataTable OldArticleReview = new DataTable();
        private List<Publication> _publicationsForReviewer;
        private Reviewer _reviewer;
        public List<Publication> PublicationsForReviewer { 
            get { return _publicationsForReviewer; }
            set {}
        }

        protected void Page_Load(object sender, EventArgs e)
        {

            //OldArticleReview = new DataTable();
            //OldArticleReview.Columns.Add("DateOldReview", typeof(string));
            //OldArticleReview.Columns.Add("URLReview", typeof(string));
            FormGridView();

             try
             {
                 _reviewer = EJournalRepository.Instance.GetReviewerByUserId(
                     Guid.Parse(Membership.GetUser().ProviderUserKey.ToString()));
                 _publicationsForReviewer = EJournalRepository.Instance.GetAllPubForReviewer(_reviewer.ReviewerId);
             }
             catch (NullReferenceException nrEx)
             {

             }
        }

        protected void FormGridView()
        {

            ArticleTable.Columns.Add("NameArticle", typeof(string));
            //ArticleTable.Columns.Add("NameJournal", typeof(string));
            ArticleTable.Columns.Add("URLArticle", typeof(string));
            ArticleTable.Columns.Add("DateArticle", typeof(string));
            ArticleTable.Columns.Add("URLNewReview", typeof(string));
            //ArticleTable.Columns.Add("OldArticleReview", typeof(DataTable));
            GridViewArticleReview.DataSource = ArticleTable;
            GridViewArticleReview.DataBind();
        }

        protected void GridViewArticleReviewOnRowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row != null)
            {
                var eee = e.Row.DataItem;
                //e.Row.DataItem = 1;
            }
        }

        protected void GridViewArticleReviewRowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //GridView InnerGridView = (GridView)e.Row.FindControl("GridViewOldReview");
                //InnerGridView.DataBind();
            }
        }

        protected void GridViewArticleReview_Load(object sender, EventArgs e)
        {
            foreach (var pub in _publicationsForReviewer)
            {
                if (EJournalRepository.Instance.IsReviewThisArticle(pub))
                {
                    //_publicationsForReviewer = EJournalRepository.Instance.GetAllPubForReviewer(_reviewer.ReviewerId);
                    ArticleTable.Rows.Add(pub.TitleRussian,// "Журнал №" /*+ EJournalRepository.Instance.GetJournalByPub(pub.Id).JournalNumber*/,
                                          @"~\Account\files\publications\" + pub.FileArticle,
                                          pub.Date.ToShortDateString(),
                                          @"~\Account\ReviewerAccount\NewReview.aspx" + "?ArticleId=" + pub.Id);
                }
                    GridViewArticleReview.DataBind();
            }
        }

        protected void GridViewArticleReview_DataBound(object sender, GridViewRowEventArgs e)
        {
            //GridView gridViewOldReview = (e.Row as GridViewRow).FindControl("GridViewOldReview") as GridView;

            //gridViewOldReview.DataSource = OldArticleReview;
            //gridViewOldReview.DataBind();

        }

        protected void GridViewArticleReview_RowCreated(object sender, GridViewRowEventArgs e)
        {

        }
    }
}